<%@page import="java.util.Date"%>
<%@page import="java.text.SimpleDateFormat"%>
<%@page import="org.json.JSONArray"%>
<%@page import="org.json.JSONObject"%>
<%@page import="ext.tianma.bom.service.sqe.SQEMaterialService"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>SQE Material</title>
<style type="text/css">
body {
    background: #ddecf5;
}
table {
    position: absolute;
    border: 1px solid #666;
    margin-left:4%;
    margin-top:6%;
    margin-bottom: 3%;
    width: 90%;
    border-collapse: collapse;
    background-color: white;
    }



td {
    vertical-align: middle;
    text-align: center;
    height: 28px;
    }
    
 

th {
    border: 1px solid #666;
    font-family: 'Microsoft YaHei';
    font-size: 17px;
    font-weight: 500;
    height: 35px;
    background-color: #eee;
}
tr:hover{
    background-color: #eee;
}
.tr1{background-color: #eee;}

.tr2{background-color: white;}
</style>
</head>

<script type="text/javascript">
window.onload = function (){
  　　var trs=document.getElementById("tb").getElementsByTagName("tr");//获取tbid的table中所有tr的信息
        for(var i=0;i<trs.length;i++)
        {
              　　　　if(i%2==0){
                  trs[i].className="tr1";
              　　　　}else{
                  trs[i].className="tr2";  
              　　　　}
        }
}
</script>
<body>
<%
JSONArray array = new JSONArray();
JSONObject object = new JSONObject();
JSONObject obj = null;
String exportToExcel = "";
String path = request.getContextPath();
request.setCharacterEncoding("utf-8");
//SQEWriteExcel.test();
String view = (String)request.getParameter("view").trim();
String number = request.getParameter("number").trim();

    object = SQEMaterialService.getShowData(number, view);

    exportToExcel = request.getParameter("exportToExcel");
    if (exportToExcel != null
            && exportToExcel.toString().equalsIgnoreCase("YES")) {
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-ddHH:mm:ss");//设置日期格式
        String dateTime = df.format(new Date());// new Date()为获取当前系统时间
        dateTime = dateTime.replace(":", "");
        String fileName = "零件批准信息_" + dateTime + ".xls";
        
        response.setContentType("application/vnd.ms-excel");
        response.setHeader("Content-Disposition", "inline; filename="+java.net.URLEncoder.encode(fileName, "UTF-8"));
    }





if("success".equals(object.getString("status"))){
    array = (JSONArray)object.get("datalist");
    
    

%>
 <table id="tb" border="2" cellpadding="1" cellspacing="1" bordercolor="#ccc">
            <tr>
                <th>序号</th>
                <th>物料编码</th>
                <th>物料名称</th>
                <th>物料描述</th>
                <th>是否专显</th>
                <th>是否需要样品承认</th>
                <th>供应商名称</th>
            </tr>
            <%
                for(int i=0; i< array.length(); i++){
                    obj = array.getJSONObject(i);
                    %>
                    <tr>
                        <td><%=i+1 %></td>
                        <td><%=obj.get("partNumber") %></td>
                        <td><%=obj.get("partName") %></td>
                        <td><%=obj.get("partDescription") %></td>
                        <td><%=obj.get("specialMonitor") %></td>
                        <td><%=obj.get("whetherPartRecognize") %></td>
                        <td><%=obj.get("partSupplier") %></td>
                    </tr>
                    
                    
                    <% 
                }
            } else{
            %>
            
                <SCRIPT language=javascript>
                    alert("该视图下不存在物料! ");
                    window.close();
                </SCRIPT>
            
            <%
            }
            %>
        </table>
        
      <%
        if (exportToExcel == null) {
    %>  
    <a href="sqeMaterial.jsp?exportToExcel=YES&view=<%=view %>&number=<%=number %>">Export to Excel</a>
    <%
        }
    %>
</body>
</html>